package mapper.WorkManagement;

import entity.Employment;
import entity.JobTendency;
import entity.WorkExp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.LinkedHashMap;
import java.util.List;

@Repository
public interface WorkMapper {

    @Insert("insert into WorkExp(userId,time,position,company,department,other,insertTime) values(#{userId},#{time},#{position},#{company},#{department},#{other},#{insertTime})")
    public int addWorkExp(WorkExp workExp);

    @Select("select expId from WorkExp where WorkExp.userId=#{userId} and insertTime=#{Time} LIMIT 1")
    public int findExpIdByTimeAndUserId(@Param("Time") String Time,@Param("userId") String userId);

    @Select("select WorkExp.*,User.name,User.icon from WorkExp,User where expId=#{expId} and WorkExp.userId = `User`.userId LIMIT 1")
    public LinkedHashMap<String,Object> findOneWorkExpByExpId(@Param("expId") String expId);

    @Insert("insert into JobTendency(userId,paycheckMin,paycheckMax,position,address,selfAssessment,insertTime) values(#{userId},#{paycheckMin},#{paycheckMax},#{position},#{address},#{selfAssessment},#{insertTime})")
    public int addJobTendency(JobTendency jobTendency);

    @Select("select TendencyId from JobTendency where JobTendency.userId=#{userId} and insertTime=#{Time} LIMIT 1")
    public int findTendencyIdByTimeAndUserId(@Param("Time") String Time,@Param("userId") String userId);

    @Select("select JobTendency.*,User.name,User.icon from JobTendency,User where TendencyId=#{TendencyId} and JobTendency.userId = `User`.userId LIMIT 1")
    public LinkedHashMap<String,Object> findOneJobTendencyByExpId(@Param("TendencyId") String TendencyId);

    @Select("select Employment.*,Enterprise.name AS enterpriseName from Employment,Enterprise where Employment.Id=#{Id} and Employment.enterpriseId = Enterprise.enterpriseId LIMIT 1")
    public LinkedHashMap<String,Object> findOneRecruitById(@Param("Id") String Id);

    @Select("select * from WorkExp where WorkExp.userId=#{userId}")
    public List<WorkExp> showWorkExp(@Param("userId") String userId);

    @Select("select * from JobTendency where JobTendency.userId=#{userId}")
    public List<JobTendency> showJobTendency(@Param("userId") String userId);

    @Insert("insert into Employment(Id,enterpriseId,name,type,expRequest,degreeRequest,address,describe,key,insertTime) values(#{Id},#{enterpriseId},#{name},#{type},#{expRequest},#{degreeRequest},#{address},#{describe},#{key},#{insertTime})")
    public int addEmployment(Employment employment);

    @Select("select Id from Employment where Employment.enterpriseId=#{enterpriseId} and Employment.insertTime = #{insertTime}")
    public String findEmploymentId(@Param("enterpriseId") String enterpriseId,@Param("insertTime") String insertTime);

//    @Select("select * from WorkExp,User where expId=#{expId} and passWord=#{passWord} ")
//    public List<LinkedHashMap<String,Object>> findOneWorkExp(@Param("userId") int expId);
}
